<?php
declare(strict_types=1);
namespace app\core;
use app\core\Container\Reflection\ReflectionContainer;
use ReflectionClass;
use ReflectionMethod;
class Proxy{
    
    private $nameSpace='';
    private $className='';
    public function __construct(){
        $table = explode("\\",strtolower(preg_replace('/(?<=[a-z])(?=[A-Z])/', '\\', get_class())));
        $reversedArray=array_reverse($table);
        $table=array_shift($reversedArray);
        $shiftedValue=array_shift($reversedArray);
        $this->className=$shiftedValue;
        $this->nameSpace=implode("\\",array_reverse($reversedArray));
     
    }
    public function __call($name, $arguments)
    { 
        $nameSpace=$this->nameSpace;
        $className=$this->className;
        $class=$nameSpace.'\\'.$className;
        $reflectedMethod= ReflectionContainer::getMethodReflection($class,$name);
       
       
        $attributes=$reflectedMethod->getAttributes();
        foreach($attributes as $k=>$v){
            $reflectedAttributionClass=ReflectionContainer::getClassReflection($v->getName());
            $reflectedAttributionClass->newInstance();
        }
        // 参考门户模式，生成代理类
        // $getDocComment=$reflectedMethod->getDocComment();
        // preg_match_all("/@param\s[a-z]{1,}(\|null)?\s\\$[a-z]{0,}/",$getDocComment,$m);
        // preg_match("/@return\s[a-z]{1,}/",$getDocComment,$returnType);
        // $params=array_shift($m);
        // print_r($params);
        // print_r($returnType);
        // print_r($getDocComment);
      return $reflectedMethod->invokeArgs(new $class,$arguments);
     
    }
}

